home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / ANS41.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  896b  |  26 lines

  1. TITLE  Square Root By Odd Numbers (ANS41.ASM)
  2.           PAGE      ,132
  3. OUR_CODE  SEGMENT   PARA 'CODE'
  4.       PUBLIC    SR32
  5. SR32      PROC      FAR
  6.           ASSUME    CS:OUR_CODE
  7.           PUSH      AX             ;Save original number
  8.       PUSH        DX
  9.       PUSH      CX             ; and CX on stack
  10.       MOV        BX,1         ;To start, (BX) = 1
  11.       SUB        CX,CX         ; and (CX) = 0
  12. AGAIN:      SUB        AX,BX         ;Subtract next odd no. from AX
  13.       SBB        DX,0         ; and DX
  14.       JC        DONE         ;Did sub. create a borrow?
  15.       INC        CX             ; No. Increment the square root,
  16.       ADD       BX,2         ;  calculate the next odd no.
  17.       JMP       AGAIN         ;  then go make next subtraction
  18. DONE:      MOV        BX,CX         ; Yes.  Transfer result to BX
  19.       POP        CX             ;  and restore the registers
  20.       POP        DX
  21.       POP       AX
  22.       RET
  23. SR32      ENDP
  24. OUR_CODE  ENDS
  25.       END       SR32
  26.